package com.leorui.schoollife.entity.response

import net.sf.json.JSONObject
import java.io.Serializable

class WeatherCommonResponse private constructor(
        var status: Int?,
        var msg: String?,
        var weather: WeatherReport?
) : Serializable {
    companion object {
        fun createResponse(status: Int?, msg: String?, temperature: Int, location: String, date: String, weatherType: String): WeatherCommonResponse {
            return WeatherCommonResponse(status, msg, WeatherReport.createWeatherReport(temperature, location, date, weatherType))
        }
    }

    fun toMap(): Map<Any?, Any?> {
        val json = JSONObject()
        json["status"] = status;
        json["msg"] = msg
        json["weather"] = weather?.toMap()
        return json.toMap()
    }
}

class WeatherReport private constructor(
        var temperature: Int, // 温度
        var location: String, // 地址信息
        var date: String, // 日期
        var weatherType: String, // 天气类型：晴天、阴天、雨天、雪天、暴雪
) : Serializable {
    companion object {
        fun createWeatherReport(temperature: Int, location: String, date: String, weatherType: String): WeatherReport {
            return WeatherReport(temperature, location, date, weatherType)
        }
    }

    fun toMap(): Map<Any?, Any?>? {
        val json = JSONObject()
        json["temperature"] = temperature
        json["location"] = location
        json["date"] = date
        json["weather_type"] = weatherType
        return json.toMap()
    }
}
